import {Component, ElementRef, OnInit, Renderer2, ViewChild} from '@angular/core';
import {ActivatedRoute, Router} from "@angular/router";
import {DialogService} from "../../../service/dialogService";
import {CCRiskControllerService} from "../../../service/CCRiskController";
import {Subject} from "rxjs/Subject";
import {UIRiskCheckPlanItem} from "../../../entity/UIRiskCheckPlanItem";
import {UIRiskCheckPlan} from "../../../entity/UIRiskCheckPlan";
import {UIRiskCheckExecution} from "../../../entity/UIRiskCheckExecution";

@Component({
  selector: 'app-risk-check-detail',
  templateUrl: './risk-check-detail.component.html',
  styleUrls: ['./risk-check-detail.component.css']
})
export class RiskCheckDetailComponent implements OnInit {

  valuesForRiskExecutionList: UIRiskCheckExecution[] = [];
  riskCheck: UIRiskCheckPlan = new UIRiskCheckPlan();
  riskCheckPlanId: number;

  valuesForRiskCheckItemList: UIRiskCheckPlanItem[] = [];

  constructor(protected a_router: Router, public element: ElementRef, private renderer: Renderer2,
              public route: ActivatedRoute, public _dialogService: DialogService, public riskService: CCRiskControllerService) {
    this.route.params.subscribe(params => {
      this.riskCheckPlanId = +params['id'];
    });
  }

  ngOnInit() {
    // this.setup();
    this.riskCheckDetail();
  }

  setup() {
    this.riskService.riskCheckExecutionList4Plan(this.riskCheckPlanId).subscribe(
      (res) => {
        this.valuesForRiskExecutionList = res;
      }
    );
  }

  riskCheckDetail() {
    this.riskService.getRiskCheckDetailById(this.riskCheckPlanId).subscribe(
      (res) => {
        this.riskCheck = res;
      }
    );
  }

  itemDetail(v: UIRiskCheckPlanItem) {
    this.a_router.navigate(['/dashboard/plan/item', v.id, 'execution']);
  }

  detail(v: UIRiskCheckExecution) {
    // TODO pass proxy and let the detail page to request more details
    this.a_router.navigate(['/dashboard/plan/execution', v.id, 'detail']);
  }

}
